import qs from 'qs'

export default $axios => ({
    getProduct(type, id) {
        return $axios.get('/server/product', {
            params: {
                type,
                keyword: id
            }
        })
    },
    getProductList(type,id){
        return $axios.get('/server/product',{
            params:{
                type,
                keyword: id
            }
        })
    },
    updateProduct(productId,category,name,description){
        return $axios.put('/server/product',qs.stringify({
            productId,
            category,
            name,
            description
        }))
    },
    deleteProduct(productId){
        return $axios.delete('/server/product',{
            params:{
                productId,
            }
        })
    },
    addProduct({productId,category,name,description,picture}){
        let pic = ''
        return picture.then((res) => {
            pic = res
            return $axios.post('/server/product',qs.stringify({
                productId,
                category,
                name,
                description,
                picture: pic
            }))
        })
    }
})
